<?php
namespace Article\Controller;
use Common\Controller\AdminBaseController;

class AdminController extends AdminBaseController{

    public function index(){
        $this->display();
    }

    /**
     * 2023.03.22，huhaiqin
     * 添加编辑文章
     */
    public function edit(){
        C('LAYOUT_NAME','layout_layui');
        if($_GET['id']){
            $m = D('Article');
            $this->info = $m->find($_GET['id']);
            $this->title = '修改文章';
        }else{
            $this->title = '添加文章';
        }
        $cat = D('Cats');
        $map = ['group_id' => D('CatsGroup')->where(['group_key'=>C('CAT_GOURP_KEY')])->limit(1)->getField('id')];
        $data = $cat->where($map)->order('listorder asc')->select();
        $curID = $this->info ? $this->info['cid'] : 0;
		foreach ($data as $r) {
			$r['selected'] = $r['id'] == $curID ? 'selected' : '';
			$array[] = $r;
		}
        $str = "<option value='\$id' \$selected>\$spacer \$cat_name</option>";
        $tree = new \Think\Tree();
		$tree->init($array);
		$select_categorys = $tree->get_tree(0, $str);
		$this->assign("select_categorys", $select_categorys);
        $this->display();
    }

    public function res(){
        $this->display();
    }

}